<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>{{ $good->title }}</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/particulars.css?v=1.0.6"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/swiper.min.css"/>
</head>
<style>
    img{ cursor: pointer;}
</style>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/iscroll.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/swiper.min.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/common.js?v=1.0.2"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<style>
    .video_play{width:60px;height:60px;position:absolute;top: 0;left: 0;bottom: 0;right:0;margin:auto;z-index:10000;border-radius:50%;display:none;}
    .loading-pay{position:absolute;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:9999;display:none;}
    .loading-pay img{width:9rem;height:2.7rem;position:absolute;left:50%;top:50%;margin-top:-1.5rem;margin-left:-4.5rem}
</style>
@if(!Auth::check())
    <script>
        var openid = '{{ env('WECHAT_APPID') }}';
        var goodsid = '{{ $_GET['good_id'] }}';
        var domain_name = '{{ env('DOMAIN_NAME') }}';
        window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+openid+"&redirect_uri=https%3A%2F%2F"+domain_name+"%2FwechatLogin%3Fproduc_id%3D"+goodsid+"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    </script>
@endif
<script>
    var count_nums = '{{ $good->count_nums }}';
    function trim(str)
    {
        return str.replace(/^\s*|\s*$/g,"")
    }
    var detail_data=[
            @foreach($infos as $info)
        [{{ $info->id }},'{{ $info->produc_type }}','{{ $info->produc_val }}',{{ $info->pid }}],
            @endforeach
        [-1,'','']
    ];
    function getGood() {
        var val='{{ env('PRODUCT_DEFAULT_IMG') }}';
        for(var i=0;i<detail_data.length;i++)
        {
            if(detail_data[i][1] == 'face' &&  detail_data[i][3] == 0)
            {
                var val = detail_data[i][2];
                return val;
            }
        }
        return val;
    }

    function getDefault(val) {
        var info = 0;
        for(var i=0;i<detail_data.length;i++){
            if(detail_data[i][1]==val && parseInt(detail_data[i][3])!=0 ){
                if(val == 'price'){
                    info =  detail_data[i][2] / count_nums;
                }else{
                    info =  detail_data[i][2];
                }
                info=Math.ceil(info*100);
                info=info*1.0/100;
                $(".pro_"+val).html('&nbsp;'+info);
                return '';
            }
        }
    }
    getDefault('price');
    function getGoodface(type) {
        var res = '';
        for(var i=0;i<detail_data.length;i++)
        {
            if(detail_data[i][1]==type )
                res += "<div class='swiper-slide' style='width:100%;'><div class='swiper-zoom-container' ><img class='swiper-lazy sw_img' data-src='{{ env('CDN_DOMAIN_NAME') }}/upload/"+detail_data[i][2]+"'><div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div></div></div>";
        }
        if(res.length == 0)
        {
            res = "<div class='swiper-slide' style='width:100%;'><div class='swiper-zoom-container' ><img class='swiper-lazy sw_img' data-src='{{ env('CDN_DOMAIN_NAME') }}/upload/{{ env('PRODUCT_DEFAULT_IMG') }}'><div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div></div></div>";
        }
        return res;
    }
    function getGoodcolor(type) {
        var res = "";
        for(var i=0;i<detail_data.length;i++)
        {
            if(detail_data[i][1]==type && parseInt(detail_data[i][3])==0 )
                res += "<li class='particulars_sum' id="+detail_data[i][0]+" style='width:3rem;'>"+detail_data[i][2]+"</li>";
        }
        return res;
    }

    $(document).on('click','.particulars_sum',function () {
        $(this).addClass("in").siblings().removeClass("in");
        $(this).css({"background":"#ea294b","color":"#fff"})
        $(this).siblings().css({"background":"#e9e9e9","color":"#383838"})
        var id = $(this).attr('id');
        var li = "";
        for(var i=0;i<detail_data.length;i++)
        {
            if(detail_data[i][3] == id && detail_data[i][1] == 'stock')
            {
                if(detail_data[i][2] > 0)   // 有库存
                {

                    $(".spinnerExample").val(1);
                    $('.increase').attr('disabled',false);
                    $('.increase').css({'background':'#fff'});
                    $('.spinnerExample').attr('disabled',false);
                    $('.spinnerExample').css({'background':'#fff'});
                }else{    //没库存
                    $('.spinnerExample').val(0);
                    $('.spinnerExample').attr('disabled',true);
                    $('.spinnerExample').css({'background':'#fff'});
                    $('.decrease').attr('disabled',true);
                    $('.increase').attr('disabled',true);
                    $('.decrease').css({'background':'#f1f1f1'});
                    $('.increase').css({'background':'#f1f1f1'});
                }
                $('.pro_stock').html('&nbsp;'+detail_data[i][2]+'&nbsp;');
            }
            if(detail_data[i][3] == id && detail_data[i][1] == 'price')
            {
                var mon=detail_data[i][2]/count_nums;
                $(this).attr("abc",mon);
                mon=Math.ceil(mon*100);
                mon=mon*1.0/100;

                $('.pro_price').html('&nbsp;'+mon+'&nbsp;' );
            }
        }
        var pro_id = '{{ $_GET['good_id'] }}';
        var msg='click color';
        $.ajax({
            url:'/productLog',
            type:'POST',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data:{pro_id:pro_id,msg:msg},
            dataType:'json',
            success:function(data){

            }
        });
    });
</script>
<body onload="loaded()">
<div id="particulars">
    <div class="wrap">
        <div class="particulars_div">
            {{--@if($good->max_order_num != null)--}}
            <div class="horn" style="display: none;">
                {{--@else--}}
                {{--<div class="horn" style="display: none">--}}
                {{--@endif--}}
                <img class="horn_img" src="img/horn.gif"/>
                <div class="horn_box" id="box">
                    <div class="scroll">
                        <ul class="horn_ul">
                            @if(count($pro_log) > 0 )
                                @foreach($pro_log as $k => $v)
                                    <li class="horn_li" abc ="{{ $v['num'] }}" status="{{ $v['status'] }}">恭喜{{ $v['user_name'] }}抢购到{{ $v['num'] }}手!</li>
                                @endforeach
                            @endif
                        </ul>
                    </div>
                </div>
            </div>
            <p class="particulars_p"><a class="particulars_a" href="/UserCenter">个人中心</a></p>
            <span class="span_people"><img src="/img/00011.png" alt="" /></span>
        </div>
        <div class="banner">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <script >document.write(getGoodface('img'));</script>
                </div>
                <!-- 如果需要分页器 -->
                <div class="swiper-pagination" style="height:1px;"></div>
                {{--<div class="bg-swiper"></div>--}}
            </div>
            <div class="particulars_name"></div>
            <div class="particulars_tit">
                <div class="tit_left">
                    <p class="tit_name">限时抢购</p>
                    <p class="tit_change"></p>
                </div>
                @if( strlen($good->start_at) >1)
                    <div class="tit_right" style="display:none">
                        <p class="tit_start">开始时间</p>
                        <p class="tit_time">00:00:00</p>
                    </div>
                @endif
            </div>
            <div class="roll">
                <div class="total">
                    <p class="total_p1"></p>
                    <div class="total_div">
                        <p class="total_p2">在线<span class="total_sp1">0</span></p>
                        <span class="total_sp2">/</span>
                        <p class="total_p3">累计<span class="total_sp3">0</span></p>
                    </div>
                </div>
                <div class="header">

                </div>
            </div>
        </div>
        <div class="par_bottom">
            <div class="bottom_t">
                <div class="particulars_price">
                    <p class="unit">￥<span class="pro_price">
                            <script style="display:none">document.write(getDefault('price'));</script>
                            </span>/件</p>
                    <p class="surplus">(剩余<span class="pro_stock">
                                <script>document.write(getDefault('stock'));</script>
                        </span>手)</p>
                    <div class="tbox" style="display: none;">
                        <div class="tiao"></div>
                        <div class="tiao_txt"></div>
                    </div>
                </div>
                <div class="particulars_number">
                    <div class="pro_div">
                        <ol class="pro_color"><script>document.write(getGoodcolor('color'));</script></ol>
                    </div>
                    <div class="spinner">
                        <button class="decrease" disabled="disabled">-</button>
                        <input type="tel" class="spinnerExample" maxlength="4" min="0" ,max="9999" step="1">
                        <button class="increase">+</button>
                    </div>
                </div>
            </div>
            <div class="bottom_b" style="clear:both">
                <div class="par_now">
                    <a href="/productLists" class="par_a articles"><img src="/img/00023.png" alt=""><p>在售商品</p></a>
                    <a href="/UserCenter/pendingPayment" class="par_a shopping"><img src="/img/00021.png" alt=""><p>购物车</p></a>
                </div>
                <div class="buy" onclick="userPurchase()">立即购买</div>
            </div>
        </div>
    </div>
    <div class="provider">
        <div class="pro_top">
{{--            @if($good->id == 33)--}}
                {{--<span style="color:#ea294b;">注:确认订单后请在24小时内完成支付</span>--}}
            {{--@else--}}
                <span style="color:#ea294b;">注:确认订单后请在10分钟内完成支付</span>
            {{--@endif--}}
            <button type="button" class="shut">×</button>
        </div>
        <div class="pro_center">
            <div class="pro_num"><p class="pro_p1">数量<span class="pro_sp">/手(1手{{ $good->count_nums }}件)</span>:</p><p class="pro_p2 order_count"></p></div>
            <div class="pro_num"><p class="pro_p1">商品价格:</p><p class="pro_p2 order_sums"></p></div>
            <div class="pro_num"><p class="pro_p1">邮费<span class="pro_sp three">(3手及以上包邮)</span>:</p><p class="pro_p2 order_postage"></p></div>
            <div class="pro_num"><p class="pro_p1">总计:</p><p class="pro_p2 order_prices" style="color:#ea294b;"></p></div>
        </div>
        <div class="pro_bottom">
            <button class="pro_a">确认订单</button>
        </div>
    </div>
    <div class="particulars_hint" style="display: none;"><p class="hint"></p></div>
    <input type="hidden" value="{{ time()*1000 }}" class="pro_time">
    <div class="choice" style="display:none;">
        <div class="choiceT">
            <span class="choice_sp1">×</span>
            <span class="choice_sp2">请选择付款方式</span>
        </div>
        <div class="choiceC">
            <p class="choice_p choice_p_wx">
                <span class="bg_sp2"></span>
                <span class="choice_sp3">微信</span>
                <span class="choice_sp4"><i class="fa fa-circle-thin"></i></span>

            </p>
            <p class="choice_p choice_p_alipay">
                <span class="bg_sp3"></span>
                <span class="choice_sp3">支付宝</span>
                <span class="choice_sp4"><i class="fa fa-circle-thin"></i></span>

            </p>
        </div>
    </div>
    <div class="mask" style="display:none"></div>
    <div class="lds-css ng-scope"><div class="lds-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>
    <div class="loading-pay">
        <img src="{{ env('CDN_DOMAIN_NAME') }}/img/payLoading.svg" alt="">
    </div>
</div>
</body>
<script>
    /*iphoneX*/
    var str= navigator.userAgent.toLowerCase();
    var ver=str.match(/cpu iphone os (.*?) like mac os/);
    if(ver && $(window).width() === 375 && $(window).height() === 724 && window.devicePixelRatio === 3){
        $(".par_bottom").css("bottom","1.408rem");
        $(".banner").css("bottom","7.803rem");
    }
    var full_order_num;
    var full_type;
    /*滚动*/
    var myScroll;
    function loaded () {
        setTimeout(function(){
            myScroll = new IScroll('.pro_div', {
                mouseWheel: true,
                click: true
            });
        },100);
    }
    document.addEventListener('touchmove', function (e) {e.preventDefault();},false);
    //判断微信终端&&android终端
    function is_android(id){
        var u = navigator.userAgent;
        var ua = navigator.userAgent.toLowerCase();
        if((ua.match(/MicroMessenger/i)=="micromessenger")&&(u.indexOf('Android')>-1)) {//判断微信终端&&android终端

        }else{
           // console.log(detail_data)
            for(var i=0;i<detail_data.length;i++){
                if(detail_data[i][1] == 'video' &&  detail_data[i][3] == 0){
                    $(".swiper-wrapper").prepend(
                            "<div class='swiper-slide' style='width:100%;'>"+
                                "<div class='swiper-zoom-container' >"+
                                    "<video id='Jvideo' src='{{env('CDN_DOMAIN_NAME') }}/upload_video/"+detail_data[i][2]+"'  preload='auto'  webkit-playsinline='webkit-playsinline' playsinline='playsinline' autoplay='true' poster type='video/mp4'  style='width:100%;height:100%;'></video>"+
                                "</div>"+
                                "<img id='video_play' class='video_play' src='/img/play.png'>"+
                            "</div>"
                    )
                }
            }
        }
    }
    is_android(".swiper-wrapper");

    /*监听微信自动播放视频*/
    function videoAutoPlay(id){
        var video = document.getElementById(id);
        video.play();
        document.addEventListener("WeixinJSBridgeReady", function () {
            video.play();
        }, false);
        document.addEventListener('YixinJSBridgeReady', function() {
            video.play();
        }, false);
        video.onended = function() {
            $(".video_play").show();
        };
    }
    for(var i=0;i<detail_data.length;i++){
        if(detail_data[i][1] == 'video' &&  detail_data[i][3] == 0){
            videoAutoPlay('Jvideo');
        }
    }
    $(document).on("click",".video_play",function(){
        $(".video_play").hide();
        videoAutoPlay('Jvideo');
    });

    //    $(".particulars_sum").eq(0).css({"background":"#ea294b","color":"#fff"});
    var pro_id = '{{ $_GET['good_id'] }}';

            @if(Auth::check())
                var userid = '{{ Auth::user()->id }}';
            @endif

            var domain_name = '{{ env('DOMAIN_NAME') }}';
    ws = new WebSocket("wss://"+domain_name+":8282");
    ws.onopen = function() {
//        ws.send('1');
    };
    ws.onmessage = function(e) {
        var data = eval("("+e.data+")");
        var type = data.type || '';
         console.log(e);
        switch(type){
            // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
            case 'init':
                // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                $.ajax({
                    url:'/websocket/joinGroup',
                    type:'POST',
                    data:{info:data.client_id,pro_id:pro_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.success == true)
                        {
                        }else{
                        }
                    }
                });
                break;
            case  'group_total':
                $('.total_sp1').text(data.line);
                $('.total_sp3').text(data.total);
                break;
            case  'login_out':
                $.ajax({
                    url:'/websocket/leaveGroup',
                    type:'POST',
                    data:{info:data.client_id,pro_id:pro_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                });
                break;
            case 'user_face_sign':
                $('.header').html('');
                @if(Auth::check())

                $('.header').html("<span class='header_sp'><img src='{{ Auth::user()->face }}'/></span>");
                        @endif

                        for(var i = 0 ; i <= data.num ;i++)
                {
                    var face = data.face[i].face;
                    var uid = data.face[i].userid

                    if(uid != userid)
                    {
                        $('.header').append("<span class='header_sp'><img src="+face+" ></span>");
                    }
                }
                break;
            case 'max_order':
                //$('.horn').show();
                var small=data.num;
                if($(".horn_li").length<=0){
                    $('.horn_ul').append("<li class='horn_li' abc ="+data.num+" status='0'>恭喜"+data.nick+"抢购到"+data.num+"手!</li>");
                }else{
                    if($(".horn_li:last").attr("abc")>=small){
                        $('.horn_ul').append("<li class='horn_li' abc ="+data.num+" status='0'>恭喜"+data.nick+"抢购到"+data.num+"手!</li>");
                        return false;
                    }else{
                        $('.horn_li').each(function () {
                            var index=$(this).index();
                            if($(this).attr("abc") < small){
                                $('.horn_ul').children(".horn_li").eq(index).before("<li class='horn_li' abc ="+data.num+" status='0'>恭喜"+data.nick+"抢购到"+data.num+"手!</li>");
                                return false;
                            }
                        })
                    }
                }
                //move();
                break;
            case 'orders_down':
                if(full_type == 2){
                    window.location.href='/pay/wechat-pay-view/'+full_order_num;
                }else if(full_type == 1){
                    window.location.href='/wecCode?ordernum='+full_order_num;
                }
                break;
            case 'orders_error':
                $('.loading-pay').hide();
                $('.hint').text('该商品已售空');
                $('.particulars_hint').show();
                setTimeout(function () {
                    $('.particulars_hint').hide();
                },1600);
                break;
            default :
        }
    };
    $('.test-buy').click(function () {
        $.ajax({
            url:'/websocket/buyTestPro',
            type:'POST',
            data:{pro_id:pro_id},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            dataType:'json',
            success:function(data){
                if(data.success == true)
                {
                }else{
                }
            }
        });
    })
</script>
<script>
    //微信接口
    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: '{{ $info_we['appId'] }}', // 必填，公众号的唯一标识
        timestamp: '{{ $info_we['timestamp'] }}', // 必填，生成签名的时间戳
        nonceStr: '{{ $info_we['nonceStr'] }}', // 必填，生成签名的随机串
        signature: '{{ $info_we['signature'] }}',// 必填，签名，见附录1
        jsApiList: [
            'checkJsApi',
            'openLocation',
            'getLocation',
            'onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
    wx.ready(function(){
        wx.checkJsApi({
            jsApiList: ['checkJsApi','openLocation','getLocation', 'onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
            success: function(res) {
//                console.log(res)
                // 以键值对的形式返回
                // ，可用的api值true，不可用为false
                // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
            }
        });
        wx.error(function(res){
//            alert('验证失败')
        });
        var imgurls = '{{ env('CDN_DOMAIN_NAME') }}';
        wx.onMenuShareAppMessage({
            title: '{{ $good->title }}', // 分享标题
            desc: '{{ $good->describe }}', // 分享描述
            link: '', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: imgurls+'/upload/'+getGood('face'), // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                // 用户确认分享后执行的回调函数
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });
    });
    var pro_id = '{{ $_GET['good_id'] }}';
    $(".articles").click(function(){
        var msg='click In selling goods';
        $.ajax({
            url:'/productLog',
            type:'POST',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data:{pro_id:pro_id,msg:msg},
            dataType:'json',
            success:function(data){

            }
        });
    });
    $(".shopping").click(function(){
        var msg='click Shopping cart';
        $.ajax({
            url:'/productLog',
            type:'POST',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data:{pro_id:pro_id,msg:msg},
            dataType:'json',
            success:function(data){

            }
        });
    });
    if($('.swiper-slide').length>1){//如果图片大于一张
        var swiper=new Swiper(".banner .swiper-container",{
            zoom:false,
            direction:"horizontal",
            // 如果需要分页器
            pagination:".swiper-pagination",
            loop:false,
            click:true,
            passiveListeners : false,
            preloadImages:false,
            lazyLoading: true,
            onSlideNextEnd: function(swiper){//轮播添加断点
                var msg='用户向右滑动一次';
                $.ajax({
                    url:'/productLog',
                    type:'POST',
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    data:{pro_id:pro_id,msg:msg},
                    dataType:'json',
                    success:function(data){

                    }
                });
            },
            onSlidePrevEnd: function(swiper){
                var msg='用户向左滑动一次';
                $.ajax({
                    url:'/productLog',
                    type:'POST',
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    data:{pro_id:pro_id,msg:msg},
                    dataType:'json',
                    success:function(data){

                    }
                });
            }
        })
        swiper.onResize();//刷新swiper
    }else{//图片为一张

        var swiper=new Swiper(".banner .swiper-container",{
            zoom:false,
            direction:"horizontal",
            loop:false,
            click:true,
            passiveListeners : false,
            preloadImages:false,
            lazyLoading: true,
        })
        swiper.onResize();//刷新swiper
    }
    $(".swiper-pagination").append("<div class='bg-swiper'></div>")
    var count=$('.swiper-slide').length;
    if(count>1){
        $('.bg-swiper').css("width",count*0.5+"rem");
    }else{
        $('.bg-swiper').css("width","0");
    }
</script>
<script>
    $(document).on("click",".company_sum",function(){
        $(this).css({"background":"#ea294b","color":"#fff"});
        $(this).siblings().css({"background":"#e9e9e9","color":"#383838"});
        $(this).addClass("click_company");
        $(this).siblings().removeClass("click_company");
    })
    is_weixn('.buy');
    is_weixn('.par_now');
    var start='{{ strtotime($good->start_at)*1000 }}';//设置开始时间戳
    var end='{{ strtotime($good->end_at)*1000 }}';//设置截止时间戳
    var now=new Date().getTime();
    if(start==0){
        $(".horn").show();
        $(".tbox").show();
    }
    if(now >= start && now <= end && start !=0 && end !=0){
        $(".horn").show();
        $(".tbox").show();
    }else if((now <start || now > end) && start !=0 && end !=0){
        $(".horn").hide();
        $(".tbox").hide();
    }
    if(now >= start && end ==0){
        $(".horn").show();
        $(".tbox").show();
    }else if(now < start && end ==0){
        $(".horn").hide();
        $(".tbox").hide();
    }

    function userPurchase() {
        //var now=new Date().getTime();
//        if((now <= start || now > end) && start !=0 && end !=0)
//        {
//            $('.hint').text('抢购尚未开始,请注意抢购时间');
//            $('.particulars_hint').show();
//            setTimeout(function () {
//                $('.particulars_hint').hide();
//            },1600);
//            return false;
//        }
        /*判断一*/
//        if(now <= start && start !=0 && end ==0){
//            $('.hint').text('抢购尚未开始,请注意抢购时间');
//            $('.particulars_hint').show();
//            setTimeout(function () {
//                $('.particulars_hint').hide();
//            },1600);
//            return false;
//        }
//        if($(".company_sum").hasClass("click_company")){
//            var company_id=$(".click_company").attr("id");
//        }else{
//            $('.hint').text('请选择代理');
//            $('.particulars_hint').show();
//            setTimeout(function () {
//                $('.particulars_hint').hide();
//            },1000);
//            return false;
//        }
        var info = filter();
        if(!info)
        {
            return false;
        }
        var nums=$(".spinnerExample").val();
        if(nums==0){
            $('.hint').text('该颜色已售罄');
            $('.particulars_hint').show();
            setTimeout(function () {
                $('.particulars_hint').hide();
            },1600);
            return false;
        }
        var pro_postage = 0;
        if(nums == 1)
        {
            pro_postage = '{{ $pro_postage[0] }}'
        }else if(nums == 2)
        {
            pro_postage = '{{ $pro_postage[1] }}'
        }

        var pri=$(".particulars_sum.in").attr("abc");
        var money=pri.trim();
        $('.order_count').text("×"+nums);
        var pro_prices = (nums*money)*count_nums;

        var floor=Math.floor(pro_prices*100)/100;
        var gross=(nums*money)*count_nums + Number(pro_postage) ;
        gross=Math.floor(gross*100)/100;
        $('.order_postage').text("￥"+pro_postage);
        $('.order_prices').text("￥"+gross);
        $('.order_sums').text("￥"+floor);
//        $('.order_prices').text("￥"+(nums*money)*7);
        $(".provider").stop().slideDown(200);

        {{--var postage = '{{ $postage }}';--}}
        {{--if(postage==1){--}}
            {{--$('.order_postage').text("￥"+0);--}}
            {{--$('.order_prices').text("￥"+floor);--}}
            {{--$(".three").hide();--}}
        {{--}else{--}}
            {{--$('.order_postage').text("￥"+pro_postage);--}}
            {{--$('.order_prices').text("￥"+gross);--}}
            {{--$(".three").show();--}}
        {{--}--}}
    }
    $(document).on("click",".pro_a",function(){
        $(this).attr("disabled","disabled");
        var that=$(this);
//        var company_id=$(".click_company").attr("id");
        var pro_id = '{{ $_GET['good_id'] }}';
        var info = filter();
        if(!info){
            return false;
        }
        var merchant_id = '{{ $good->merchant_id}}';
        var num  =trim($('.spinnerExample').val());
        $('.choice').show();
        $('.mask').show();
        that.removeAttr("disabled","disabled");
        $(".provider").stop().slideUp(200);
        $('.choice_p_wx').click(function(){
            $('.choice').hide();
            $('.mask').hide();
            $('.loading-pay').show();
            $.ajax({
                url:'/userPurchase',
                type:'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                data:{info:info,pro_id:pro_id,merchant_id:merchant_id,num:num,company_id:0},
                dataType:'json',
                success:function(data){
                    if(data.success == true){
                        // window.location.href='/pay/wechat-pay-view/'+data.order_num;
                        full_order_num=data.order_num;
                        full_type=2;
                    }else{
                        that.removeAttr("disabled","disabled");
                        if(data.msg == 'login')
                        {
                            self.location='/user-login';
                            return;
                        }
                        $('.loading-pay').hide();
                        $('.hint').text(data.msg);
                        $('.particulars_hint').show();
                        setTimeout(function () {
                            $('.particulars_hint').hide();
                        },1600);
                    }
                }
            })
        });
        $('.choice_p_alipay').click(function(){
            $('.choice').hide();
            $('.mask').hide();
            $('.loading-pay').show();
            $.ajax({
                url:'/userPurchase',
                type:'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                data:{info:info,pro_id:pro_id,merchant_id:merchant_id,num:num,company_id:0},
                dataType:'json',
                success:function(data){
                    if(data.success == true){
                        that.removeAttr("disabled","disabled");
                        // $(".provider").stop().slideUp(200);
                        // window.location.href='/wecCode?ordernum='+data.order_num;
                        full_order_num=data.order_num;
                        full_type=1;
                    }else{
                        that.removeAttr("disabled","disabled");
                        if(data.msg == 'login')
                        {
                            self.location='/user-login';
                            return;
                        }
                        $('.loading-pay').hide();
                        $('.hint').text(data.msg);
                        $('.particulars_hint').show();
                        setTimeout(function () {
                            $('.particulars_hint').hide();
                        },1600);
                    }
                }
            })
        });
        $('.choice_sp1').click(function(){
            $('.choice').hide();
            $('.mask').hide();
        });
    })
    $(".shut").click(function(){
        $(".provider").stop().slideUp(200);
    })
    function filter() {
        var color_id = 0;
        $('.particulars_sum').each(function () {
            if(this.style.color == 'rgb(255, 255, 255)'){
                color_id  = $(this).attr('id');
            }
        });
        if(color_id > 0)
        {
            return color_id;
        }else{
            $('.hint').text('请选择颜色');
            $('.particulars_hint').show();
            setTimeout(function () {
                $('.particulars_hint').hide();
            },1000);
            return false;
        }
    }
    /*限时抢购*/
    function countTime(){
//      var now=new Date().getTime();//当前时间戳
        var now = $('.pro_time').val();
        var rel_time = parseInt(now) + parseInt(1000)
        $('.pro_time').val(rel_time)
        var h,m,s;
        if (now<=start){
            $(".tit_change").html("未开始");
            $(".tit_right").show();
            h = Math.floor((start-now)/1000/60/60);
            m = Math.floor((start-now)/1000/60%60);
            s = Math.floor((start-now)/1000%60);

            $(".tit_time").html(add_zero(h)+":"+add_zero(m)+":"+add_zero(s));
            /*不能点购买*/
        };
        if(end !=0){
            if((now>start)&&(now<=end)){
                $(".tit_change").html("抢购中");
                $(".tit_start").html("结束倒计时");
                $(".particulars_name").css({"background":"#F64268","opacity":"0.7"});
                $(".tit_right").show();
                h = Math.floor((end-now)/1000/60/60);
                m = Math.floor((end-now)/1000/60%60);
                s = Math.floor((end-now)/1000%60);
                $(".tit_time").html(add_zero(h)+":"+add_zero(m)+":"+add_zero(s));
            };
            if(now>end){
                $(".tit_change").html("已结束");
                $(".particulars_name").css({"background":"#000","opacity":"0.3"});
                $(".tit_right").hide();
                clearInterval(timer);
                /*不能购买*/
            }
        }else{
            if(now>start){
                $(".tit_change").html("抢购中");
                $(".tit_right").hide();
                $(".particulars_name").css({"background":"#F64268","opacity":"0.7"});
            }
            if(start==0){
                $(".particulars_name").css({"background":"#F64268","opacity":"0.7"});
            }
        }
    }
    timer = setInterval(countTime,1000);
    /*倒计时加零*/
    function add_zero(n){
        return n < 10 ? '0'+ n : n;
    }

    function getServerDate(){
        return new Date($.ajax({async: false}).getResponseHeader("Date"));
    }

    /*数量加减*/
    if($('.pro_stock').text()!=0){
        $('.spinnerExample').val(1);
    }else{
        $('.spinnerExample').val(0);
        $('.increase').attr('disabled',true);
        $('.increase').css({'background':'#f1f1f1'});
        $('.spinnerExample').attr('disabled',true);
        $('.spinnerExample').css({'background':'#fff'});
    }
    $('.increase').click(function(){//加
        numAdd();
        var pro_id = '{{ $_GET['good_id'] }}';
        var msg='click increase Number';
        $.ajax({
            url:'/productLog',
            type:'POST',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data:{pro_id:pro_id,msg:msg},
            dataType:'json',
            success:function(data){

            }
        });

    });
    $('.decrease').click(function(){//减
        numDec();
        var pro_id = '{{ $_GET['good_id'] }}';
        var msg='click decrease Number';
        $.ajax({
            url:'/productLog',
            type:'POST',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data:{pro_id:pro_id,msg:msg},
            dataType:'json',
            success:function(data){

            }
        });
    });

    $('.spinnerExample').focus(function(){
        $(this).val('');
        $('.decrease').attr('disabled',false);
        $('.decrease').css({'background':'#fff'});
        $('.increase').attr('disabled',false);
        $('.increase').css({'background':'#fff'});
    }).blur(function(){
        var value=$('.spinnerExample').val();
        var num=$('.surplus .pro_stock').text();

        if(isNaN(value)||parseInt(value)!=value||parseInt(value)<=0||value==''){
            $('.spinnerExample').val(1);
            $('.decrease').attr('disabled',true);
            $('.decrease').css({'background':'#f1f1f1'});
        }
        if((parseInt(value)>=parseInt(num))){
            $('.spinnerExample').val(num.trim());
            $('.increase').attr('disabled',true);
            $('.increase').css({'background':'#f1f1f1'});
        }
        $('.increase').click(function(){//加

        })
    });
    function numAdd(){/*商品数量+1*/
        var value=$('.spinnerExample').val();
        var num=$('.surplus .pro_stock').text();
        var num_add=parseInt(value)+1;
        if(num_add>=parseInt(num)){
            $('.increase').attr('disabled',true);
            $('.increase').css({'background':'#f1f1f1'});
            $('.spinnerExample').val(num.trim());
        }else{
            $('.decrease').attr('disabled',false);
            $('.decrease').css({'background':'#fff'});
            $('.spinnerExample').val(num_add);
        }
    }
    function numDec(){/*商品数量-1*/
        var value =$('.spinnerExample').val();
        var num=$('.surplus .pro_stock').text();
        var num_dec = parseInt(value)-1;
        if(num_dec==1){
            $('.decrease').attr('disabled',true);
            $('.decrease').css({'background':'#f1f1f1'});
        }
        if(num_dec>0){
            $('.spinnerExample').val(num_dec);
            $('.increase').attr('disabled',false);
            $('.increase').css({'background':'#fff'});
        }
    }
    //    喇叭广播效果
    //    function move(){
    //            var sum=$('.horn_li').length;
    //            if($(".horn_li:first").attr("status")==1){
    //                $(".horn_ul").stop(true,true).animate({'marginLeft': -12*sum+"rem"}, 5555*sum,'linear',function(){
    //                    $(".horn_ul").css('marginLeft',1+"rem");
    //                    $(".horn_ul").children('.horn_li').eq(0).remove();
    //                })
    //            }else{
    //                $(".horn_ul").stop(true,true).animate({'marginLeft': -12*sum+"rem"}, 5555*sum,'linear',function(){
    //                    $(".horn_ul").css('marginLeft',1+"rem");
    //                })
    //            }
    //            setTimeout(function(){
    //                move();
    //            },5555*sum)
    //        }
    //        move();
    function move(){
        var width=$(".horn_ul").width()+200;
        var sum=$('.horn_li').length;
        if($(".horn_li:first").attr("status")==1){
            $(".horn_ul").stop(true,true).animate({'marginLeft':-width}, 5555*sum,'linear',function(){
                $(".horn_ul").css('marginLeft',10);
                $(".horn_ul").children('.horn_li').eq(0).remove();
            })
        }else{
            $(".horn_ul").stop(true,true).animate({'marginLeft': -width}, 5555*sum,'linear',function(){
                $(".horn_ul").css('marginLeft',10);
            })
        }
        setTimeout(function(){
            move();
        },5555*sum)
    }
    move();
    /*剩余总数*/
    var stock_num=0;
    for(var k=0;k<detail_data.length;k++){
        if(detail_data[k][1]=='stock'){
            //console.log(detail_data[k][2]);
            stock_num+=parseInt(detail_data[k][2]);
        }
    }
    $(".pro_stock").html('&nbsp;'+stock_num+'&nbsp;');
    /*库存剩余进度条*/
    var count_hand='{{$good->total_stock}}';//总
    //console.log(count_hand)
    var percent=(stock_num/count_hand).toFixed(2);
    //console.log(percent);
    if(percent<=0){
        $(".tiao").css("width",0+"rem").html();
        $(".tiao_txt").text("库存仅剩0%")
    }else if(percent<=0.01 && percent>0){
        $(".tiao").css("width",0.06+"rem").html();
        $(".tiao").css({"height":0.3+"rem","margin-top":0.1+"rem"}).html();
        $(".tiao_txt").text("库存仅剩1%")
    }else if(percent>0.01 && percent<=1){
        $(".tiao").css("width",(percent*6)+"rem").html();
        $(".tiao_txt").text("库存仅剩"+Math.ceil(percent*100)+"%")
    }else if(percent>1){
        $(".tiao").css("width",6+"rem").html();
        $(".tiao_txt").text("库存仅剩100%");
    }
    if(stock_num<=0){
        $(".tiao").css("width",0+"rem").html();
        $(".tiao_txt").text("库存仅剩0%");
    }
</script>
</html>
